package cn.itcast.service.impl;


import cn.hutool.core.util.ObjectUtil;
import cn.itcast.dao.Sys_permissionDao;
import cn.itcast.entity.PageResult;
import cn.itcast.pojo.Permission;
import cn.itcast.service.Sys_permissionService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

@Service(version = "1.0.0")
public class Sys_permissionServiceImpl implements Sys_permissionService {
    @Autowired
    private Sys_permissionDao syspermissionDao;
    @Override
    public PageResult queryPermissionList(Integer page, Integer pageSize, String queryString) {
        PageHelper.startPage(page,pageSize);
        Page<Permission> permissions = this.syspermissionDao.selectByCondition(queryString);
        return new PageResult(permissions.getTotal(),permissions);
    }


    @Override
    public List<Permission> queryPermissionList(Integer page,Integer pageSize){
        return this.syspermissionDao.findAll();
    }

    @Override
    public Boolean savePermissions(Map<String, String> map) {
        String name = map.get("name");
        String keyname = map.get("keyword");
        String textarea = map.get("textarea");
        Permission permission = new Permission();
        permission.setName(name);
        permission.setKeyword(keyname);
        permission.setDescription(textarea);
        return this.syspermissionDao.add(permission);
    }

    @Override
    public Permission queryEditPermissions(Integer id) {
        return this.syspermissionDao.findById(id);
    }

    @Override
    public Boolean editPermissions(Permission permission) {
        if(ObjectUtil.isEmpty(permission)){
            return false;
        }
        return this.syspermissionDao.update(permission);
    }

    @Override
    public Boolean delPermissions(Integer id) {
        return this.syspermissionDao.deleteById(id);
    }

    @Override
    public List<Permission> queryPermissionsAll() {
        List<Permission> all = this.syspermissionDao.findAll();
        return all;
    }


}
